<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title></title>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all"/>
    <style>
        .layui-form-item .layui-input-inline {
            width: 150px;
        }
        .layui-form-label {
            padding: 9px 5px;
            width: auto;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title layui_tab_title">
                <li><a href="{:url('gift/index')}">礼物配置</a></li>
                <li class="layui-this"><a href="{:url('props/index')}">道具</a></li>
                <li><a href="{:url('gold/index')}">金币配置</a></li>
                <li><a href="{:url('vip/index')}">VIP配置</a></li>
            </ul>
        </div>
        <div class="layui-card-body">
            <div style="padding-bottom: 10px;">
                <button class="layui-btn layuiadmin-btn-gift" onclick="add()">添加</button>
            </div>
            <table id="demo" lay-filter="demo"></table>
        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: "/layuiadmin/", //静态资源所在路径
    }).extend({
        index: "lib/index", //主入口模块
    }).use(["table", 'form'], function () {
        $ = layui.jquery, form = layui.form, table = layui.table;
        table.render({
            elem: '#demo',
            id: '#demo',
            url: '/admin/props/index',
            defaultToolbar: [
                'filter', 'print', {title: '提示', layEvent: 'LAYTABLE_EXCEL', icon: 'layui-icon-table'},
            ],
            page: false,
            method: "get",
            text: {
                none: '暂无相关数据！'//默认无数据
            },
            response: {
                statusName: 'code',
                statusCode: 0,
                msgName: 'msg',
                countName: 'count',
                dataName: 'list',
            },
            cols: [[ //表头
                {field: 'id', title: 'ID', width: "8%", align: "center",},
                {field: 'name', title: '道具名称', width: "16%", align: "center",},
                {field: 'icon', title: '图标', width: "15%", align: "center",templet: function (d) {
                        if (d.icon) {
                            return '<img style="display: inline-block; width: auto; height: 100%;" src="' + d.icon + '" >';
                        }
                        return '无';
                    }
                },
                {field: 'type_text', title: '功能属性', width: "15%", align: "center"},
                {field: 'remark', title: '说明',  align: "center",},
                {field: 'weight', width: "12%",title: '操作',align: "center",templet: function (item) {
                        return '<a class="layui-btn  layui-btn-xs" onclick="edit(' + item['id'] + ')"><i class="layui-icon"></i>编辑</a> ';
                    }
                },
            ]],
            // done: function (res, curr, count) {
            //     res.list.forEach(function (item, index) {
            //
            //     });
            // },
        });
    });

    function edit(id) {
        layer.open({
            type: 2,
            title: ["编辑", 'font-size:16px'],
            content: '/admin/props/edit?id=' + id,
            area: ['620px', '435px'],
            //offset: '0px',
        });
    }

    /*添加*/
    function add() {
        layer.open({
            type: 2,
            title: ["添加", 'font-size:16px'],
            content: '/admin/props/add',
            area: ['620px', '435px'],
            //offset: '0px',
        });
    }

    function status(id, status) {
        var title = '确认要下架吗？';
        if (status == 1) {
            title = '确认要上架吗？';
        }
        layer.confirm(title, {icon: 6}, function () {
            $.ajax({
                type: "POST", //请求方式
                url: '/admin/props/status', //请求地址
                dataType: "json", //返回的数据类型
                data: {"id":id,"status":status}, //数据
                //请求成功
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1, time: 2000}, function () {
                            window.location.reload();
                        });
                    } else {
                        layer.msg(data.msg, {icon: 2, time: 5000});
                    }
                },
            });
        });
    }

</script>
</body>
</html>
